package com.cykj.faceledtv.data;

import android.content.Context;

import com.cykj.faceledtv.data.db.DbHelper;
import com.cykj.faceledtv.data.db.model.UserData;
import com.cykj.faceledtv.data.pref.PreferencesHelper;
import com.cykj.faceledtv.di.ApplicationContext;
import com.cykj.faceledtv.network.ApiHelper;


import javax.inject.Inject;
import javax.inject.Singleton;


/**
 * 数据访问管理总接口实现,所有项目数据层都通过该方式实现
 *
 * @author jzh
 * @date 2018/12/11 17:10
 */
@Singleton
public class AppDataManager implements DataManager {
    private final Context mContext;
    private final DbHelper mDbHelper;
    private final ApiHelper mApiHelper;
    private final PreferencesHelper mPreferencesHelper;

    @Inject
    public AppDataManager(@ApplicationContext Context context, DbHelper dbHelper,
                          ApiHelper apiHelper,
                          PreferencesHelper preferencesHelper) {
        mContext = context;
        mDbHelper = dbHelper;
        mPreferencesHelper = preferencesHelper;
        mApiHelper = apiHelper;
    }

    @Override
    public void setLoginId(String loginId) {
        mPreferencesHelper.setLoginId(loginId);
    }

    @Override
    public String getLoginId() {
        return mPreferencesHelper.getLoginId();
    }

    @Override
    public void setLoginPassword(String password) {
        mPreferencesHelper.setLoginPassword(password);
    }

    @Override
    public String getLoginPassword() {
        return mPreferencesHelper.getLoginPassword();
    }

    @Override
    public void setInOutAdv(String adv) {
        mPreferencesHelper.setInOutAdv(adv);
    }

    @Override
    public String getInOutAdv() {
        return mPreferencesHelper.getInOutAdv();
    }

    @Override
    public void setFreeAdv(String adv) {
        mPreferencesHelper.setFreeAdv(adv);
    }

    @Override
    public String getFreeAdv() {
        return mPreferencesHelper.getFreeAdv();
    }

    @Override
    public void setAddress(String address) {
        mPreferencesHelper.setAddress(address);
    }

    @Override
    public String getAddress() {
        return mPreferencesHelper.getAddress();
    }

    @Override
    public void setSiteName(String siteName) {
        mPreferencesHelper.setSiteName(siteName);
    }

    @Override
    public String getSiteName() {
        return mPreferencesHelper.getSiteName();
    }


    @Override
    public boolean insertOrReplaceUserData(UserData userData) {
        return mDbHelper.insertOrReplaceUserData(userData);
    }

    @Override
    public boolean deleteUserDataById(Long id) {
        return mDbHelper.deleteUserDataById(id);
    }

    @Override
    public boolean deleteAllUserData() {
        return mDbHelper.deleteAllUserData();
    }

    @Override
    public UserData getUserDataById(Long id) {
        return mDbHelper.getUserDataById(id);
    }
}
